//
//  STHairerInfoView.m
//  YiYueHairdresser
//
//  Created by zhouzhouzhou on 2018/10/10.
//  Copyright © 2018年 YuYiLian. All rights reserved.
//

#import "STHairerInfoView.h"

#import "STHairerHeaderCell.h"
#import "STDoorSimpleCell.h"
#import "UIButton+ZYHblock.h"
#import "STHairSerCell.h"


@implementation STHairerInfoView

-(void)setHairerView{
    [self loadHouseView];
}

-(void)loadHouseView{
    
    sectionHeaderNames = @[@"",@"",@"服务项目",@"TA的套餐",@"入驻门店",@"顾客评价",@"他的作品"];
    
    if(!hairInfoTableView){
        hairInfoTableView = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
        hairInfoTableView.delegate = self;
        hairInfoTableView.dataSource = self;
        hairInfoTableView.separatorStyle = UITableViewCellSelectionStyleNone;
        hairInfoTableView.backgroundColor = [UIColor clearColor];
        hairInfoTableView.tableFooterView = [UIView new];
        [hairInfoTableView registerNib:[UINib nibWithNibName:@"STNameHeaderCell" bundle:nil] forCellReuseIdentifier:@"STNameHeaderCell"];
        [hairInfoTableView registerClass:STShouldEditCell.class forCellReuseIdentifier:@"STShouldEditCellID"];
        [self addSubview:hairInfoTableView];
    }else{
        hairInfoTableView.frame =self.bounds;
        [hairInfoTableView reloadData];
    }
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return sectionHeaderNames.count + 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0 || section == 1|| section == 2) {
        return 1;
    }
    else if (section ==3){
        //服务类型列表
        return self.hairerInfoData.cardServerItems.count+2;
    }else if (section ==4){
        //套餐列表
        return self.hairerInfoData.cardPackages.count+1;
    }else if (section ==5){
        //入驻门店列表
        return self.hairerInfoData.cardStoreDTOs.count+1;
    }else if (section ==6){
        //评价列表
        return self.hairerInfoData.cardGradeDTOs.count+1;
    }else if (section ==7){
        return 2;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0){
            return 250;
        }else if (indexPath.row ==1){
            return 100;
        }
    }else if (indexPath.section == 1 ){
        return 40;
    }else if (indexPath.section == 2 ){
        return 40;
    }
    else if (indexPath.section ==3 || indexPath.section ==4){
        return 44;
    }else if (indexPath.section ==5){
        return 75;
    }else if (indexPath.section ==6){
        return 150;
    }else if (indexPath.section ==7){
        return 250;
    }
    return 0;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell * cell;
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0){
            NSString * identifier = @"STHairerHeaderCell";
            STHairerHeaderCell * hairerCell = [tableView dequeueReusableCellWithIdentifier:identifier];
            if (!hairerCell) {
                hairerCell = [[STHairerHeaderCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
            }
            [hairerCell setHeaderViewWithData:self.hairerInfoData];
            return hairerCell;
        }else if (indexPath.row ==1){
            static NSString * advIdentifier = @"advIdentifier";
            cell = [tableView dequeueReusableCellWithIdentifier:advIdentifier];
            if (!cell) {
                cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:advIdentifier];
            }
            [self setDoorSerWithData:self.hairerInfoData.cardServerItems cell:cell indexPath:indexPath ];
            if (![cell.contentView.subviews containsObject:volumeColView]) {
                [cell.contentView addSubview:volumeColView];
            }
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
    }
    else if (indexPath.section == 1 || indexPath.section == 2){
        
        STNameHeaderCell * hairerCell =[tableView dequeueReusableCellWithIdentifier:@"STNameHeaderCell"];
        [hairerCell.nameBtn setTitle:sectionHeaderNames[indexPath.section-1] forState:UIControlStateNormal];
        return hairerCell;
    }
    else if (indexPath.section ==3 ){
        if (indexPath.row == 0) {
            STNameHeaderCell * hairerCell =[tableView dequeueReusableCellWithIdentifier:@"STNameHeaderCell"];
            [hairerCell.nameBtn setTitle:sectionHeaderNames[indexPath.section-1] forState:UIControlStateNormal];
            return hairerCell;
        }else if (indexPath.row == self.hairerInfoData.cardServerItems.count +1){
            STShouldEditCell *cell = [tableView dequeueReusableCellWithIdentifier:@"STShouldEditCellID" forIndexPath:indexPath];
            cell.editIndexPath = indexPath;
            cell.editDelegate = self;
            return cell;
        }
        static NSString * advIdentifier = @"serIdentifier";
        STHairSerCell * hairerCell = [tableView dequeueReusableCellWithIdentifier:advIdentifier];
        if (!hairerCell) {
            hairerCell = [[STHairSerCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:advIdentifier];
        }
        STHairServerModel * model = self.hairerInfoData.cardServerItems[indexPath.row-1];
        [hairerCell setHairSerCell:model];
        return hairerCell;
    }else if (indexPath.section ==4){
        
        if (indexPath.row == 0) {
            STNameHeaderCell * hairerCell =[tableView dequeueReusableCellWithIdentifier:@"STNameHeaderCell"];
            [hairerCell.nameBtn setTitle:sectionHeaderNames[indexPath.section-1] forState:UIControlStateNormal];
            return hairerCell;
        }
        
        static NSString * advIdentifier = @"advIdentifier";
        cell = [tableView dequeueReusableCellWithIdentifier:advIdentifier];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:advIdentifier];
        }
        STHairPackageModel * model = self.hairerInfoData.cardPackages[indexPath.row-1];
        cell.textLabel.text = model.name;
        cell.detailTextLabel.text =[NSString stringWithFormat:@"¥%0.2f",model.price];
//        [cell.headImg sd_setImageWithURL:[NSURL URLWithString:model.picture] placeholderImage:[UIImage imageNamed:@"m-add"]];
        cell.textLabel.font =FONT(14);
        cell.detailTextLabel.font =FONT(14);
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }else if (indexPath.section ==5){
        if (indexPath.row == 0) {
            STNameHeaderCell * hairerCell =[tableView dequeueReusableCellWithIdentifier:@"STNameHeaderCell"];
            [hairerCell.nameBtn setTitle:sectionHeaderNames[indexPath.section-1] forState:UIControlStateNormal];
            return hairerCell;
        }
        
        static NSString * identifier = @"STDoorSimpleCell";
        STDoorSimpleCell * hairerCell =[tableView dequeueReusableCellWithIdentifier:identifier];
        if (!hairerCell) {
            hairerCell = [[STDoorSimpleCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
        }
        STHairStoreModel * model = self.hairerInfoData.cardStoreDTOs[indexPath.row-1];
        [hairerCell setDoorSimpleCellWithData:model];
        return hairerCell;
    }else if (indexPath.section ==6){
        if (indexPath.row == 0) {
            STNameHeaderCell * hairerCell =[tableView dequeueReusableCellWithIdentifier:@"STNameHeaderCell"];
            [hairerCell.nameBtn setTitle:sectionHeaderNames[indexPath.section-1] forState:UIControlStateNormal];
            return hairerCell;
        }
        
        static NSString * evaIdentifier = @"evaIdentifier";
        STDoorEvaCell * hairerCell =[tableView dequeueReusableCellWithIdentifier:evaIdentifier];
        if (!hairerCell) {
            hairerCell = [[STDoorEvaCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:evaIdentifier];
        }
//        [hairerCell setEvaluateView:self.hairerInfoData];
        WeakSelf
        hairerCell.commentBtn.didSelectBtn = ^(UIButton *sender) {
            [weakSelf actionTurnToAllCommentVC];
        };
        return hairerCell;
    }else if (indexPath.section ==7){
        static NSString * proIdentifier = @"advIdentifier";
        cell = [tableView dequeueReusableCellWithIdentifier:proIdentifier];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:proIdentifier];
        }
//        [self seHairProWithData:self.hairerInfoData.cardOpusDTOs indexPath:indexPath];
        if(![cell.contentView.subviews containsObject:hairProImgView]){
             [cell.contentView addSubview:hairProImgView];
        }
    }
    return cell;
    
}

//优惠卷
-(SHChangeSizeScrollView *)setDoorSerWithData:(id)data cell:(UITableViewCell*)cell indexPath:indexPath{
    if (!volumeColView) {
//        NSArray * arr =rowHeight[indexPath.section];
//        NSNumber * height =arr[indexPath.row];
        volumeColView=[[SHChangeSizeScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
        volumeColView.delegate = self;
        volumeColView.isChangeSize = NO;
        volumeColView.intervalWight = 10;
        volumeColView.showBounds = CGRectMake(0, 0, 80, 100);
        [volumeColView setScrollViewWithArrData:data];
    }
    return volumeColView;
}

-(STHairProImgView *)seHairProWithData:(id)data indexPath:(NSIndexPath *)indexPath{
    if(!hairProImgView){
        hairProImgView=[[STHairProImgView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH*0.1, 250*0.1, SCREEN_WIDTH*0.8, 250*0.8)];
        [hairProImgView setHairProjectImgWithData:data];
        WeakSelf
        hairProImgView.moreBtn.didSelectBtn = ^(UIButton * sender) {
            
            if ([weakSelf.delegate respondsToSelector:@selector(hairerInfoViewTurnToAllProjectVC)]) {
                [weakSelf.delegate hairerInfoViewTurnToAllProjectVC];
            }
        };
    }else{
        [hairProImgView setHairProjectImgWithData:data];
    }
    return hairProImgView;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = UIView.new;
    view.backgroundColor = BgColor;
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10.0f;
}
-(void)actionTurnToAllCommentVC{
    if ([self.delegate respondsToSelector:@selector(hairerInfoViewTurnToAllCommentVC)]) {
        [self.delegate hairerInfoViewTurnToAllCommentVC];
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    if (indexPath.section == 3) {
//        if ([self.delegate respondsToSelector:@selector(hairerInfoViewSignHouseSelNum:)]) {
//            [self.delegate hairerInfoViewSignHouseSelNum:(int)indexPath.row];
//        }
//    }
}

#pragma mark - cell点击前往编辑 delegate
-(void)hairShouldEditDelegate:(NSIndexPath *)indexPath
{
    if (indexPath.section == 3 && indexPath.row == self.hairerInfoData.cardServerItems.count +1) {
        DLog(@"服务项目前往编辑%ld--%ld",indexPath.section,indexPath.row);
    }
}

@end
